package com.gqh.weather.controller;

import com.gqh.weather.exception.Result;
import com.gqh.weather.service.ScoreTeacherService;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 评分教师管理控制器
 */
@Slf4j
@RestController
@RequestMapping("/pingjia/zh/v1/pc_subtask/score_teacher")
@Validated
public class ScoreTeacherController {

    @Autowired
    private ScoreTeacherService scoreTeacherService;

    /**
     * 保存阅卷配置数据
     *
     * @param pcSubtaskId 机试子任务ID
     * @param configData 阅卷配置数据
     * @return 保存结果
     */
    @PostMapping("/save_config")
    public Result<Void> saveConfig(
            @RequestParam("pc_subtask_id") @NotNull Integer pcSubtaskId,
            @RequestParam("config_data") @NotNull String configData) {
        log.info("保存阅卷配置数据，机试子任务ID: {}", pcSubtaskId);
        try {
            scoreTeacherService.saveConfig(pcSubtaskId, configData);
            return Result.success(null);
        } catch (Exception e) {
            log.error("保存阅卷配置数据失败", e);
            return Result.error("保存阅卷配置数据失败: " + e.getMessage());
        }
    }
    
    /**
     * 开始阅卷
     *
     * @param pcSubtaskId 机试子任务ID
     * @return 开始阅卷结果
     */
    @PostMapping("/score")
    public Result<Void> beginScore(
            @RequestParam("pc_subtask_id") @NotNull Integer pcSubtaskId) {
        log.info("开始阅卷，机试子任务ID: {}", pcSubtaskId);
        try {
            scoreTeacherService.beginScore(pcSubtaskId);
            return Result.success(null);
        } catch (Exception e) {
            log.error("开始阅卷失败", e);
            return Result.error("开始阅卷失败: " + e.getMessage());
        }
    }
    
//    /**
//     * 开始复评
//     *
//     * @param pcSubtaskId 机试子任务ID
//     * @return 开始复评结果
//     */
//    @PostMapping("/review")
//    public Result<Void> beginReview(
//            @RequestParam("pc_subtask_id") @NotNull Integer pcSubtaskId) {
//        log.info("开始复评，机试子任务ID: {}", pcSubtaskId);
//        try {
//            scoreTeacherService.beginReview(pcSubtaskId);
//            return Result.success(null);
//        } catch (Exception e) {
//            log.error("开始复评失败", e);
//            return Result.error("开始复评失败: " + e.getMessage());
//        }
//    }
    
    /**
     * 导出阅卷老师信息
     *
     * @param pcSubtaskId 机试子任务ID
     * @return 导出结果
     */
    @PostMapping("/export")
    public Result<String> export(
            @RequestParam("pc_subtask_id") @NotNull Integer pcSubtaskId) {
        log.info("导出阅卷老师信息，机试子任务ID: {}", pcSubtaskId);
        try {
            String fileUrl = scoreTeacherService.export(pcSubtaskId);
            return Result.success(fileUrl);
        } catch (Exception e) {
            log.error("导出阅卷老师信息失败", e);
            return Result.error("导出阅卷老师信息失败: " + e.getMessage());
        }
    }
}